home *** CD-ROM | disk | FTP | other *** search
/ New Star Software Collection / NSS_Collection.iso / 3-170 dbase 10 for windows / 1.ima / DOC.PAK / QUERY.TXT < prev    next >
Encoding:
Text File  |  1993-07-26  |  14.4 KB  |  371 lines

  1. Copyright (c) 1991-1993 Borland International, Inc.  All Rights Reserved.
  2.  
  3.               INTRODUCTION TO THE QUERY DESIGNER
  4.               ----------------------------------
  5.  
  6. This paper describes the current status of the Bladerunner
  7. Query Designer, including features not yet implemented.  
  8.  
  9.  
  10. Contents
  11. --------
  12. I.    Design Goals
  13. II.   How to Start the Query Designer
  14. III.  Basic Query Layout
  15. IV.   Fields List
  16. V.    Table Relations
  17. VI.   Sort Criteria
  18. VII.  Filter Conditions
  19. VIII. Features Not Implemented Yet
  20.  
  21. Design Goals
  22. ------------
  23.  
  24. The Blade Runner Query Designer pursues these objectives:
  25.  
  26. Similarity to dBASE IV -- It is a more modern, graphical
  27. version of the dBASE IV Query Designer.  It retains as much
  28. functionality as possible from dBASE IV.  Where practical,
  29. it uses the same concepts, keystrokes, and terminology as
  30. dBASE IV.  However, this goal does not bar innovative new
  31. features or adherence to normal Windows behavior.
  32.  
  33. Suitable for Views and Queries -- Like dBASE IV, it is
  34. suitable for view definition and query specification.  For
  35. this reason, it creates updatable views whenever possible.
  36.  
  37. Generate dBASE Program Files -- Like dBASE IV, the query
  38. designer's output is a .QBE file containing a dBASE program.  
  39. The resulting code can readily work in a customer's
  40. application.  
  41.  
  42. Multiple Simultaneous Queries -- Unlike dBASE IV, the Query
  43. Designer is non-modal.  A user can design multiple queries
  44. simultaneously.
  45.  
  46. How to Start the Query Designer
  47. -------------------------------
  48.  
  49. You can start the Query Designer in one of the following ways:
  50.  
  51. - From the menu bar, choose File|New|Query
  52. - In the Command window, enter: CREATE QUERY or MODIFY QUERY
  53. - In the File Viewer, click on the Queries icon, then the Untitled
  54.   query icon.
  55.  
  56.  
  57. Basic Query Layout
  58. ------------------
  59.  
  60. Like dBASE IV, the Query Designer is a separate MDI window
  61. containing a table UI object for each table involved in the
  62. query.  The table UI object is a schematic representation of
  63. a database table and lists the field names contained in the
  64. table.  Most of the interaction with the Query Designer is
  65. by direct manipulation of the table objects.  There is also
  66. a menu and SpeedBar that contain actions specific to the
  67. Query Designer.
  68.  
  69. The Query Designer initially starts out empty (with no
  70. tables) unless an existing query is being modified.  Tables
  71. are added to a query by the Query | Add Table menu or SpeedBar
  72. button.  New tables are added below any existing tables in
  73. the designer window.  Tables can be removed from a query by
  74. choosing Query | Remove Table or clicking the first button from 
  75. the right on the SpeedBar.
  76.  
  77. If there are multiple tables displayed in the Query Designer, one
  78. of them is the currently selected table.  Menu and SpeedBar actions
  79. that apply to a single table operate on the currently
  80. selected table.  The selected table is identified by a
  81. blinking cursor in one of its fields.  The currently
  82. selected table can be changed by the F3 (previous) and F4
  83. (next) keys or by clicking on the table with the mouse.
  84.  
  85. If the Query window contains more tables than can be
  86. displayed vertically, a vertical scroll bar appears
  87. automatically.  If a table UI object is wider than the query
  88. window, it can be scrolled horizontally using tab keys
  89. and/or clicking the scroll arrows just to the right of the
  90. table name.  The designer automatically scrolls table UI
  91. objects and fields into view as necessary.
  92.  
  93. Fields within a table UI object all start out at the same
  94. default width (unrelated to the size of the field data). 
  95. The size of any field column can be modified by dragging the
  96. column divider between field names in the top row of the
  97. table UI object.  As filter conditions are added into the column,
  98. the column width automatically expands to display the entire
  99. filter condition.  The order of the field columns can be modified
  100. by dragging a field name horizontally to a new position
  101. (similar to BROWSE).
  102.  
  103. There are three possible outputs from the Query Designer
  104. that are available at any time:
  105.  
  106. 1) Save .QBE File.  Choose File|Save to create a dBASE program 
  107. file that sets up the dBASE environment to correspond with the
  108. query when executed. You must give the file an extension.
  109.  
  110. 2) Run Query.  Choose View|Run Query to convert the Query window 
  111. into a Browse window within an environment that corresponds to 
  112. the query.  (Note: Currently, the browse appears in a separate
  113. window.)
  114.  
  115. 3) Create Result Table.  This action creates a table that
  116. contains the results from evaluating the query.
  117.  
  118. Fields List
  119. -----------
  120.  
  121. Fields are selected into a query in a manner very similar to
  122. dBASE IV.  Individual fields can be selected (or unselected)
  123. by tabbing to the field and pressing F5 or by checking (or
  124. unchecking) the checkbox in the row below the field names. 
  125. All of the fields in a table can be selected (or unselected)
  126. by tabbing to the table name column and pressing F5 or by
  127. checking (or unchecking) the checkbox below the table name.
  128.  
  129. Field selection is not echoed in the Command window on a
  130. field by field basis.  An appropriate SET FIELDS command is
  131. either generated into the .QBE file or executed immediately
  132. before switching to the browse.  This is required to support
  133. multiple simultaneous queries.
  134.  
  135. If no fields are selected into a query, then all fields are
  136. assumed to be included in the view (by SET FIELDS TO).
  137.  
  138. Table Relations
  139. ---------------
  140.  
  141. The Blade Runner Query Designer has an explicit interface
  142. for creating table relationships (it doesn't use example
  143. elements).  This is a more natural way to specify and
  144. display relationships between tables.
  145.  
  146. A relationship is defined by dragging the mouse between the
  147. parent table name and the child table name.  The cursor
  148. changes shape during this operation to give visual feedback
  149. that a relationship is being defined.  Once the drag has
  150. been completed, a dialog box appears to gather information
  151. necessary to relate the tables.
  152.  
  153. The Define Link dialog has two ways to specify the master
  154. expression for the relation.  A field name can be selected
  155. from a listbox to create a relation based on a single field
  156. value.  Alternatively, for dBASE tables only, a master
  157. expression can be entered in an entry field to control the
  158. relation.  The Expression Expert is available at this time
  159. to help the user construct a valid dBASE expression.  (Note:
  160. This second option has not been fully implemented.)
  161.  
  162. The Define Link dialog also provides a means to specify
  163. the index to be used for the child table.  An index
  164. expression can be selected from a listbox to select the
  165. controlling index for the child table.  This list box
  166. contains all possible index expressions for the child table
  167. and includes indexes from associated .NDX and .MDX files. 
  168. This selected index order is immediately used by echoing an
  169. appropriate SET ORDER command to the Command window.
  170.  
  171. When the Define Link dialog appears while constructing a
  172. relation, it is initialized with default values, if
  173. possible.  A default value is detected when a child index
  174. expression has the same name and data type as a field in the
  175. parent table.  (Note: This feature has not been
  176. implemented.)
  177.  
  178. Once a relationship has been defined, the Query Designer
  179. indents the child table under the parent table and draws an
  180. arrow between them.  Tables are automatically rearranged
  181. within the query window, if necessary, to move the child
  182. table as close as possible to the parent table (so lines
  183. don't cross over other tables).
  184.  
  185. A previously defined relationship can be inspected or
  186. modified by selecting the child table and using the
  187. Properties | Relation menu command or by right-clicking the
  188. child table name.  The same Define Link dialog box is
  189. used for this purpose as for the initial creation.
  190.  
  191. Sort Criteria
  192. -------------
  193.  
  194. The sort order for each table is controlled using multiple
  195. choice checkboxes preceding the field names in the table UI
  196. objects.  Each field in a table can individually be set to
  197. one of three states: 1) off, 2) ascending, or 3) descending. 
  198. Like dBASE IV, a field may be involved in determining sort
  199. order without being selected into the result set (fields
  200. list).
  201.  
  202. When a table is added to a query, it defaults to natural
  203. order with all of the sort checkboxes set to "off."  The
  204. sort checkbox for any field can be toggled by selecting the
  205. field and pressing F6 or by selecting a choice from a pop-up
  206. menu that appears with a left mouse click.  (Note:
  207. Currently, child tables in a relation do not permit
  208. modification of the sort order.)
  209.  
  210. For dBASE and Paradox tables, there may be maintained
  211. indexes which are based on a single field.  Such fields have
  212. a key symbol next to the sort checkbox in the table UI
  213. object to indicate that the table may be sorted most
  214. efficiently using one of these fields.
  215.  
  216. The resulting dBASE code to implement a sort on a table
  217. depends on the number and type of sort fields specified by
  218. the user.  There are three basic situations:
  219.  
  220. 1) Natural Order or Existing Index.  When no sort order is
  221. specified or when a maintained index can be used, the table
  222. is opened with the appropriate ORDER clause.
  223.  
  224. The following code is generated when no sort fields are
  225. specified or when an existing index expression can be used:
  226.  
  227.    CLOSE DATABASES
  228.    SET EXACT ON
  229.    SELECT 1
  230.    USE CONTACT.DBF ORDER COMPCODE
  231.    GO TOP
  232.  
  233. 2) Single Field.  When a single field is specified to
  234. determine sort order for which an index expression does not
  235. exist, a temporary index is created.  The temporary index is
  236. created in an .MDX file in the current directory with the
  237. name ~QBEn, where n is the work area number.  The temporary
  238. index file is automatically deleted when the table is closed
  239. using the NOSAVE option.
  240.  
  241. The following code is generated when a single sort field is
  242. specified:
  243.  
  244.    CLOSE DATABASES
  245.    SET EXACT ON
  246.    SELECT 1
  247.    USE COMPANY.DBF EXCLUSIVE
  248.    INDEX ON CITY TAG CITY OF ~QBE0001
  249.    CLOSE DATABASES
  250.    USE COMPANY.DBF
  251.    SET ORDER TO CITY OF ~QBE0001 NOSAVE
  252.    GO TOP
  253.  
  254. 3) Multiple Fields.  When more than one field is specified
  255. to determine sort order, a sorted intermediate table is
  256. created.  The order of the fields in the table UI object
  257. determine their precedence in the sort.  The relative
  258. precedence of fields can be controlled by rearranging the
  259. fields within the table UI object.  The sorted table is 
  260. created in the current directory with the name ~SORTn, where 
  261. n is the work area number.  The intermediate table is 
  262. automatically deleted when the table is closed using the 
  263. NOSAVE option.
  264.  
  265. The following code is generated when multiple sort fields are specified:
  266.  
  267.    CLOSE DATABASES
  268.    SET EXACT ON
  269.    SELECT 1
  270.    USE COMPANY.DBF
  271.    SET FILTER TO
  272.    GO TOP
  273.    SORT TO ~SORT001 ON CITY,ZIP
  274.    USE ~SORT001 ALIAS COMPANY NOSAVE NOUPDATE
  275.    GO TOP
  276.  
  277. Filter Conditions
  278. -----------------
  279.  
  280. Like dBASE IV, query filter conditions are entered in the rows
  281. beneath the field names in the table UI object.  Each
  282. expression should evaluate to a logical and be of the form:
  283.  
  284.    <comparison operator> <value expression>
  285.    which implies:
  286.    (current field) <comparison operator> <value expression>
  287.  
  288. If the operator is omitted, an equal operator is assumed. 
  289. The value expression should be of the same type as the
  290. current field.  Like dBASE IV, string constants must be
  291. enclosed in quote marks.
  292.  
  293. More than one filter condition can be entered into a single field
  294. separated by commas.  All filter conditions entered on the same
  295. row are combined by logical AND operators.  Additional
  296. condition rows may be added by the down arrow key.  (Empty
  297. rows on the bottom are automatically removed by the up arrow
  298. key.)  If there are conditions in more than one row, these
  299. are combined by logical OR operators.
  300.  
  301. Filter expressions are checked for errors at the time
  302. they are entered (when the user attempts to leave the
  303. field).  Invalid expressions are highlighted for the user to
  304. fix and are not included in the generated .QBE file output. 
  305. (Note: Error messages will show in the status bar when an
  306. error is detected.)
  307.  
  308. Like dBASE IV, conditions for related tables are included
  309. in the filter expression of the parent table.  In these
  310. situations, the parent filter expression also contains a
  311. FOUND function to insure that a child record exists (inner
  312. join).
  313.  
  314. The following code is generated when a condition exists in
  315. both a parent and child table:
  316.  
  317.    CLOSE DATABASES
  318.    SET EXACT ON
  319.    SELECT 1
  320.    USE COMPANY.DBF
  321.    USE CONTACT.DBF IN 2 ORDER COMPCODE
  322.    SET RELATION TO COMPCODE INTO CONTACT
  323.    SET FILTER TO FOUND(2) .AND. COMPANY>"C" .AND.
  324.       CONTACT->DUMMY>"N"
  325.    GO TOP
  326.  
  327. Unlike dBASE IV, Blade Runner always filters database
  328. records using SET FILTER logic.  (dBASE IV also supports the
  329. use of SET KEY and FOR..WHILE, as well.)  Blade Runner uses
  330. SET FILTER to insure that queries work well in a multiuser
  331. environment and to allow filter optimization to occur within
  332. the ODAPI database engine.
  333.  
  334. Features Not Implemented Yet
  335. ----------------------------
  336.  
  337. The following features will be supported in Bladerunner,
  338. but are not operative at this time:
  339.  
  340. Calculated Fields -- An interface will be provided to allow
  341. specification of a calculated field derived from other data.
  342. Calculated fields will be placed into an additional table UI
  343. object.  The form of this specification is a dBASE
  344. expression which is included in the fields list.
  345.  
  346. Renamed Fields -- An interface will be provided to allow
  347. specification of a different name for a field.  The result
  348. is very similar to a calculated field included in the fields
  349. list.
  350.  
  351. Condition Box -- A condition box, similar to dBASE IV, will
  352. be provided to specify additional conditions that cannot be
  353. specified within a single field condition (i.e.
  354. FIELD1>FIELD2).
  355.  
  356. Sorting Child Tables -- The appropriate logic to permit
  357. sorting within related tables will be determined and
  358. implemented.
  359.  
  360. Design versus Run Mode -- The UI model for Bladerunner
  361. calls for a mode change between design and run to occur
  362. within the same window.  Currently, a separate Browse window
  363. is created rather than reusing the query design window.
  364.  
  365. Non-modal Behavior -- Unlike dBASE IV, the Bladerunner
  366. Query Designer is non-modal.  This creates situations where
  367. the user can make changes to tables involved in a query from
  368. outside of the Query Designer (i.e. close a table from the
  369. Command window).  These situations must be adequately
  370. detected and resolved or else be prevented from occurring.
  371.